package com.yami.shop.rights.common.listener;

import com.yami.shop.bean.event.ProdDetailEvent;
import com.yami.shop.bean.vo.ProdDetailVo;
import com.yami.shop.rights.common.service.ProdRightsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 获取权益商品信息
 */

@Slf4j
@Component("ProdDetailListener")
@AllArgsConstructor
public class ProdDetailListener {

    @Autowired
    private ProdRightsService prodRightsService;

    @EventListener(ProdDetailEvent.class)
    public void getProdRights(ProdDetailEvent event) {
        try {
            List<ProdDetailVo> prodDetail = prodRightsService.getProdDetail(event.getVrSceneDetail().getRightsId());
            event.getVrSceneDetail().setProdDetailVos(prodDetail);
        } catch (Exception e) {
            log.error("获取权益商品信息失败:", e);
        }
    }

}
